package com.agile.leetcode.designmodel.builder;

import java.util.Date;

/**
 * lomBook builder注解创建内部类实现构建者模式的模仿与实现
 *
 * @Author:ChenZhangKun
 * @Date: 2021/4/30 16:57
 */
public class BuilderModel {
    @Override
    public String toString() {
        return "BuilderModel{" +
                "id=" + id +
                ", name='" + name + '\'' +
                ", content='" + content + '\'' +
                ", type=" + type +
                ", status=" + status +
                ", finishDate=" + finishDate +
                '}';
    }

    private long id;
    private String name;
    private String content;
    private int type;
    private int status;
    private Date finishDate;

    /**
     * 外部类构造方法
     *
     * @param id
     * @param name
     * @param content
     * @param type
     * @param status
     * @param finishDate
     */
    public BuilderModel(long id, String name, String content, int type, int status, Date finishDate) {
        this.id = id;
        this.name = name;
        this.content = content;
        this.type = type;
        this.status = status;
        this.finishDate = finishDate;
    }

    /**
     * 返回内部类
     *
     * @return
     */
    public static BuilderModel.Builder builder() {
        return new BuilderModel.Builder();
    }

    public static void main(String[] args) {
        BuilderModel builderModel = BuilderModel.builder()
                .id(1L)
                .name("czk")
                .content("love")
                .type(1)
                .status(1)
                .date(new Date())
                .build();
        System.out.println(builderModel);
    }

    /**
     * 定义静态内部类
     * 将成员变量全部考入
     */
    public static class Builder {
        private long id;
        private String name;
        private String content;
        private int type;
        private int status;
        private Date finishDate;

        /**
         * 方法
         *
         * @param id
         * @return
         */
        public BuilderModel.Builder id(Long id) {
            this.id = id;
            return this;
        }

        public BuilderModel.Builder name(String name) {
            this.name = name;
            return this;
        }

        public BuilderModel.Builder content(String content) {
            this.content = content;
            return this;
        }

        public BuilderModel.Builder type(Integer type) {
            this.type = type;
            return this;
        }

        public BuilderModel.Builder status(Integer status) {
            this.status = status;
            return this;
        }

        public BuilderModel.Builder date(Date date) {
            this.finishDate = date;
            return this;
        }

        public BuilderModel build() {
            return new BuilderModel(this.id, this.name, this.content, this.type, this.status, this.finishDate);
        }
    }

    public BuilderModel() {
    }


}
